package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SupplierServiceImpl implements ISupplierService {

    @Autowired
    private ISupplierMapper mapper;


    @Override
    public IPage<SupplierBean> findByItem(Integer pageNO, String name, String scope) {
        QueryWrapper<SupplierBean> qw = new QueryWrapper<>();
        if (name != null && name.length() != 0) {
            qw.like("s_name", name);
        }
        if (scope != null && scope.length() != 0) {
            qw.like("s_scope", scope);
        }

        return mapper.selectPage(new Page(pageNO, 5), qw);
    }

    @Override
    public SupplierBean findById(Integer supplierId) {
        return mapper.selectById(supplierId);
    }

    @Override
    public void update(Integer supplierId, String person, String phone) {
        SupplierBean supplierBean = mapper.selectById(supplierId);
        supplierBean.setUser(person);
        supplierBean.setPhone(phone);
        mapper.updateById(supplierBean);

    }

    @Override
    public void add(SupplierBean supplier) {
        mapper.insert(supplier);
    }

    @Override
    public void addList(List<SupplierBean> list) {
        mapper.addList(list);
    }

    @Override
    public List<SupplierBean> findAll() {
        return mapper.findAll();
    }
}
